package com.ms.es.result.impl;

import com.ms.common.constant.BaseStatusCode;
import com.ms.common.exception.NormalException;
import com.ms.es.enums.EsActionEnum;
import com.ms.es.result.EsResultHandler;

public class ResultHandlerFactory {

    public static EsResultHandler createEsReultHandler(EsActionEnum commandType) {
        EsResultHandler esResultHandler;
        switch (commandType) {
            case SEARCH:
                esResultHandler = new EsSearchResultHandler();
                break;
            case SEARCH_PAGE:
                esResultHandler = new EsSearchPageResultHandler();
                break;
            case UPDATE_BY_QUERY:
            case DELETE_BY_QUERY:
                esResultHandler = new EsOperateByQueryResultHandler();
                break;
            case BULK_INSERT:
            case BULK_UPDATE:
                esResultHandler = new EsBulkResultHandler();
                break;
            case INSERT_BY_ID:
                esResultHandler = new EsInsertByIdResultHandler();
                break;
            case UPDATE_BY_ID:
                esResultHandler = new EsUpdateByIdResultHandler();
                break;
            case SEARCH_BY_ID:
                esResultHandler = new EsSearchByIdResultHandler();
                break;
            case DELETE_BY_ID:
                esResultHandler = new EsDeleteByIdResultHandler();
                break;
            case SEARCH_BY_SQL:
                esResultHandler = new EsSqlResultHandler();
                break;
            case ANALYZE_TEXT:
                esResultHandler = new EsAnalyzerResultHandler();
                break;
            default:
                throw new NormalException(BaseStatusCode.NOT_FOUND);
        }
        return esResultHandler;
    }

}
